﻿//-----------------------------------------------------------------------
// <copyright file="UnitTestShouldNotContainIf.cs" company="COMPANY">
//     Copyright (c) COPYRIGHT. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace CodeQualityExtension.UnitTestRules
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using CodeQualityExtension.Framework;
    using Microsoft.FxCop.Sdk;
    
    /// <summary>
    /// Checks whether unit tests do not contain any loops
    /// </summary>
    public class UnitTestShouldNotContainIf : BaseRule
    {
        /// <summary>
        /// Initializes a new instance of the UnitTestShouldNotContainIf class
        /// </summary>
        public UnitTestShouldNotContainIf()
            : base(typeof(UnitTestShouldNotContainIf))
        {
        }

        /// <summary>
        /// Checks all visible members (classes, methods...)
        /// </summary>
        public override TargetVisibilities TargetVisibility
        {
            get
            {
                return TargetVisibilities.All;
            }
        }

        /// <summary>
        /// Calls VisitMethod on all unit test methods
        /// </summary>
        /// <param name="member">FxCop member instance</param>
        /// <returns>Collection of problems</returns>
        public override ProblemCollection Check(Member member)
        {
            Method method = member as Method;

            if (method != null && InternalUtilities.IsTestMethod(method))
            {
                VisitMethod(method);
            }

            return this.Problems;
        }

        /// <summary>
        /// Creates an analysis problem if branch statement is found
        /// </summary>
        /// <param name="branch">FxCop branch instance</param>
        public override void VisitBranch(Branch branch)
        {
            if (branch != null)
            {
                // TODO: finish
                //// SourceContext enables to display hyperlink to place where branch is located
                ////Problem problem = new Problem(
                ////    GetResolution(),
                ////    branch.SourceContext);

                ////this.Problems.Add(problem);
            }

            base.VisitBranch(branch);
        }
    }
}
